package com.leyou.item.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Override
    public List<CategoryDTO> queryCategoryByPid(Long pid) {
        List<Category> categories = query().eq("parent_id", pid).list();
//        List<CategoryDTO> categoryDTOS=new ArrayList<>();
//////        for (Category category : categories) {
//////            CategoryDTO ca = new CategoryDTO();
//////            BeanUtils.copyProperties(category,ca);
//////            categoryDTOS.add(ca);
//////        }
        return CategoryDTO.convertEntityList(categories);
    }

    @Override
    public CategoryDTO queryCategoryById(Long id) {
        return new CategoryDTO(getById(id));
    }

    @Override
    public List<CategoryDTO> queryCategoryByIds(List<Long> ids) {
        return CategoryDTO.convertEntityList(listByIds(ids));
    }

    @Override
    public List<CategoryDTO> queryCategoryByBrand(Long bid) {

        return CategoryDTO.convertEntityList(this.getBaseMapper().queryCategoryByBrand(bid));
    }
}